//
//  UIViewController+Router.m
//  Express
//
//  Created by lhongl on 2025/9/28.
//  Copyright © 2025 QM. All rights reserved.
//

#import "UIViewController+Router.h"
#import <objc/runtime.h>

static const void *blockKey = &blockKey;
@implementation UIViewController (Router)

- (void)setFailureBlock:(void (^)(NSString *))failureBlock {
    objc_setAssociatedObject(self, blockKey, failureBlock, OBJC_ASSOCIATION_COPY);
}

- (void (^)(NSString *))failureBlock {
    return objc_getAssociatedObject(self, blockKey);
}


- (void)setValue:(id)value forKey:(NSString *)key failure:(void (^)(NSString *))fail {
    self.failureBlock = fail;
    [self setValue:value forKey:key];
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
#ifdef DEBUG
    [super setValue:value forUndefinedKey:key];
#endif
    if (self.failureBlock) {
        self.failureBlock(key);
    }
}

@end
